package avicit.bdp.dgs.mdm.rest;

import avicit.bdp.dgs.mdm.dto.MDataDTO;
import avicit.bdp.dgs.mdm.dto.MdataApplicationDTO;
import avicit.bdp.dgs.mdm.dto.MdataRApplicationDTO;
import avicit.bdp.dgs.mdm.service.MdataApplicationService;
import avicit.platform6.core.rest.msg.QueryRespBean;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @金航数码科技有限责任公司
 * @作者：${tableInfo.classCreator}
 * @邮箱：${tableInfo.classMailbox}
 * @创建时间： 2023-12-06 11:02
 * @类说明：
 * @修改记录：
 */
@RestController
@Api(tags = "调用系统")
@RequestMapping("/api/bdp/dgs/mdm/application")
public class MdataApplicationRest {

    private static final Logger logger = LoggerFactory.getLogger(MdataApplicationRest.class);

    @Autowired
    private MdataApplicationService mdataApplicationService;

    @ApiOperation(value = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "查询关键词", name = "keyWords", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "当前页", name = "pageNo", dataType = "Int", paramType = "query"),
            @ApiImplicitParam(value = "每页大小", name = "pageSize", dataType = "Int", paramType = "query")
    })
    @GetMapping("/getPageList")
    public ResponseMsg<QueryRespBean<MdataApplicationDTO>> getPageList(
            @RequestParam(required = false) String keyWords,
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize) throws Exception {
        ResponseMsg<QueryRespBean<MdataApplicationDTO>> responseMsg = new ResponseMsg<>();
        QueryRespBean<MdataApplicationDTO> queryRespBean = mdataApplicationService.getPageList(keyWords, pageNo, pageSize);
        responseMsg.setResponseBody(queryRespBean);
        return responseMsg;
    }

    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public ResponseMsg<String> save(@RequestBody MdataApplicationDTO dto) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataApplicationService.save(dto));
        return responseMsg;
    }

    @ApiOperation(value = "修改")
    @PutMapping("/update")
    public ResponseMsg<Boolean> update(@RequestBody MdataApplicationDTO dto) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        mdataApplicationService.update(dto);
        responseMsg.setResponseBody(true);
        return responseMsg;
    }

    @ApiOperation(value = "通过ID查询")
    @GetMapping("/queryById")
    public ResponseMsg<MdataApplicationDTO> queryById(@ApiParam(value = "id", name = "id") @RequestParam String id) {
        ResponseMsg<MdataApplicationDTO> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataApplicationService.queryById(id));
        return responseMsg;
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/deleteById")
    public ResponseMsg<Boolean> deleteById(@RequestBody MdataApplicationDTO dto) throws Exception{
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        mdataApplicationService.deleteById(dto);
        return responseMsg;
    }

    @ApiOperation(value = "启用停用")
    @PostMapping("/updateStatus")
    public ResponseMsg<Boolean> updateStatus(@RequestBody MdataApplicationDTO dto) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        mdataApplicationService.updateStatus(dto);
        responseMsg.setResponseBody(true);
        return responseMsg;
    }

    @ApiOperation(value = "查询系统列表")
    @GetMapping("/queryList")
    public ResponseMsg<List<MdataApplicationDTO>> queryList() {
        ResponseMsg<List<MdataApplicationDTO>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataApplicationService.queryList());
        return responseMsg;
    }

    @ApiOperation(value = "查询所有系统列表")
    @GetMapping("/queryAllList")
    public ResponseMsg<List<MdataApplicationDTO>> queryAllList() {
        ResponseMsg<List<MdataApplicationDTO>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataApplicationService.queryAllList());
        return responseMsg;
    }

    @ApiOperation(value = "查询主数据列表")
    @GetMapping("/queryMDataList")
    public ResponseMsg<List<MDataDTO>> queryMDataList() {
        ResponseMsg<List<MDataDTO>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataApplicationService.queryMDataList());
        return responseMsg;
    }

    @ApiOperation(value = "根据系统ID查询主数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "系统ID", name = "applicationId", dataType = "String", paramType = "query")
    })
    @GetMapping("/queryMDataListByAppId")
    public ResponseMsg<List<MdataRApplicationDTO>> queryMDataListByAppId(@RequestParam String applicationId) {
        ResponseMsg<List<MdataRApplicationDTO>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(mdataApplicationService.queryMDataListByAppId(applicationId));
        return responseMsg;
    }

}
